package cn.javaweb.servlet;

import cn.javaweb.entity.Course;
import cn.javaweb.entity.User;
import cn.javaweb.library.AjaxResult;
import cn.javaweb.model.CourseModel;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;

@WebServlet("/student/course")
public class CourseServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        CourseModel courseModel = new CourseModel();

        User user = (User) req.getAttribute("user");

        HashMap<String, Object> data = new HashMap<String ,Object>();

        List<Course> rows = courseModel.getCourseList(user);

        HashMap<String, Object> stat = new HashMap<String, Object>();
        stat.put("qq",courseModel.getStatistic("qq", user.getId()));
        stat.put("all",courseModel.getStatistic("all", user.getId()));
        stat.put("cd",courseModel.getStatistic("cd", user.getId()));
        stat.put("qj",courseModel.getStatistic("qj", user.getId()));


        data.put("rows", rows);
        data.put("statistic",stat);

        resp.getWriter().print(AjaxResult.success("操作成功", data ));


    }
}
